package org.alanlau.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定向交换机路由
 *
 * @author alan
 * @version 1.0
 * @date 2021/4/8 17:04
 */
@Configuration
public class RoutingDirectConfig {
    /**
     * 声明交换机
     *
     * @return 交换机
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("boot.directs");
    }

    /**
     * 声明队列1 绑定info 和 warm
     *
     * @return 队列1
     */
    @Bean
    public Queue directQueue1() {
        return QueueBuilder.durable("boot.directQueue1").build();
    }

    /**
     * 声明队列2
     *
     * @return 队列2
     */
    @Bean
    public Queue directQueue2() {
        return QueueBuilder.durable("boot.directQueue2").build();
    }

    /**
     * 把队列1绑定到交换机里面指定info的路由key
     *
     * @return 交换机
     */
    @Bean
    public Binding binding1() {
        return BindingBuilder.bind(directQueue1()).to(directExchange()).with("info");
    }

    /**
     * 把队列2绑定到交换机里面指定error的路由key
     *
     * @return 交换机
     */
    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("error");
    }
}
